#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

int main() {
  Mat src = imread("../images/2.jpg");
  if (src.empty()) {
    cout << "could not load image.." << endl;
    return -1;
  }
  namedWindow("opencv setup demo", CV_WINDOW_AUTOSIZE);
  imshow("opencv setup demo", src);

  Mat dst;
  dst = Mat(src.size(), src.type());
  dst = Scalar(127, 0, 255);
  //   namedWindow("output", CV_WINDOW_AUTOSIZE);
  //   imshow("output", dst);

  Mat dst1;
  src.copyTo(dst1);
  //   namedWindow("output1", CV_WINDOW_AUTOSIZE);
  //   imshow("output1", dst1);

  Mat dst2;
  cvtColor(src, dst2, CV_BGR2GRAY);
  //   namedWindow("output2", CV_WINDOW_AUTOSIZE);
  //   imshow("output2", dst2);
  cout << "src channels:" << src.channels() << endl;
  cout << "dst2 channels:" << dst2.channels() << endl;

  const uchar* firstrow = src.ptr<uchar>(0);
  cout << "first pixel values:" << static_cast<uint32_t>(*firstrow) << endl;

  int cols = src.cols;
  int rows = src.rows;
  cout << "cols:" << cols << " rows: " << rows << endl;

  Mat M(300, 300, CV_8UC3, Scalar(255, 0, 0));
  //   cout << "M=" << M << endl;
  // namedWindow("output3", CV_WINDOW_AUTOSIZE);
  // imshow("output3", M);
  Mat m1;
  m1.create(src.size(), src.type());
  m1 = Scalar(0, 0, 255);
  //   imshow("output3", m1);

  //　定义小数组
  Mat kernel = (Mat_<float>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
  filter2D(src, dst, -1, kernel);
  //   imshow("output3", dst);

  Mat m2 = Mat::zeros(src.size(), src.type());
//   imshow("output3", m2);

  Mat m3 = Mat::eye(2,2,CV_8UC1);
  cout << "m3=" << endl << m3 << endl;


  waitKey(0);
  return 0;
}